﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BamM.WServices.MS;
using System.IO;
using System.Xml;


namespace bamM.Controllers
{
    public class BaseController : Controller
    {
        private ViewSummaryList summary = null;       
        public JsonResult GetQueryFileNames(string viewName, string activityName)
        {
            List<SelectListItem> queryFileNames = new List<SelectListItem>();

            DirectoryInfo dirInfo = new DirectoryInfo(@"C:\bamM\" + viewName + "\\" + activityName + "\\");
            //Assuming Test is your Folder
            FileInfo[] Files = dirInfo.GetFiles("*.*"); //Getting Text files
            int count = 0;
            foreach (FileInfo file in Files)
            {
                
                queryFileNames.Add(new SelectListItem() { Text = file.Name, Value = file.FullName });
                count++;
            }

            return Json(new SelectList(queryFileNames, "Value", "Text"));
        }

        public JsonResult GetActivities(string id)
        {
            List<SelectListItem> activities = new List<SelectListItem>();
            BamM.WServices.MS.BamManagementServiceSoapClient client = new BamM.WServices.MS.BamManagementServiceSoapClient();
            summary = client.GetViewSummaryForCurrentUser();
            int count = 0; 
            foreach (var item in summary.View.Where(m => m.Name.Equals(id)))
            {
                
                foreach (var c in item.Activity)
                {
                    
                    activities.Add(new SelectListItem() { Text = c.Name, Value = count.ToString() });
                    count++;
                }
            }
           return Json(new SelectList(activities, "Value", "Text"));
        }

        public JsonResult GetViewNames()
        {
            BamM.WServices.MS.BamManagementServiceSoapClient client = new BamM.WServices.MS.BamManagementServiceSoapClient();
            summary = client.GetViewSummaryForCurrentUser();
            List<SelectListItem> viewNames = new List<SelectListItem>();
            int count = 0;
            foreach (var d in summary.View)
            {                
                viewNames.Add(new SelectListItem() { Text = d.Name, Value = count.ToString() });
                count++;                
            }
            
            return Json(new SelectList(viewNames, "Value", "Text"));
        }

        


    }
}